
<?php
include '../phpFunctions/randomPassword.php';
$myPassword = generatePassword();
$newPassword = hash( 'whirlpool', $myPassword);
$newPassword = substr($newPassword, 0, 75);

$anvandarnamn=$_POST['anvandarnamn'];
$to=$_POST['mail'];



include '../phpFunctions/databaseConnect.php';
         $result = mysql_query("select username from users where username = '$anvandarnamn'");
         $row = mysql_fetch_assoc($result);
         $username = $row["username"];

         $result = mysql_query("select username from users where email = '$to'");
         $row = mysql_fetch_assoc($result);
         $correctmailuser = $row["username"];






         
if (count($username)==1 && $username==$correctmailuser){
$subject = 'Dinkonst.se: Nytt lösenord';
$message = "Du har beställt ett nytt lösenord till dinkonst.se \r\n
            Användarnamn: $anvandarnamn
            Nytt lösenord: $myPassword";
$headers = 'From: Dinkonst.se' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
$result = mysql_query("UPDATE users
                       set password = '$newPassword'
                       where username = '$anvandarnamn'
                        ");

    include '../LogIn/generateNewPassword_sucess.php';

}
else {
    include '../LogIn/generateNewPassword_fail.php';
//    print 'hej';


}

mysql_close();

?>
